package com.witmed.lib_common.utils

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.witmed.lib_common.R

@GlideModule
class ImageUtils:AppGlideModule() {

    companion object{
        @JvmStatic
        fun loadIamgeRound(context: Context,url:String,iv:ImageView){
            val options = RequestOptions().transform(CenterCrop(),RoundedCorners(30))
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)

            Glide.with(context)
                .load(url)
                .error(R.drawable.ic_launcher_background)
                .placeholder(R.drawable.ic_launcher_background)
                .apply(options)
                .into(iv)
        }

        @JvmStatic
        fun loadIamge(context: Context,url:String,iv:ImageView){
            val options = RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)

            Glide.with(context)
                .load(url)
                .error(R.drawable.ic_launcher_background)
                .placeholder(R.drawable.ic_launcher_background)
                .apply(options)
                .into(iv)
        }

        @JvmStatic
        fun loadIamgeCircle(context: Context,url:String,iv:ImageView){
            val options = RequestOptions().transform(CenterCrop(),CircleCrop())
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)

            Glide.with(context)
                .load(url)
                .error(R.drawable.ic_launcher_background)
                .placeholder(R.drawable.ic_launcher_background)
                .apply(options)
                .into(iv)
        }
    }


}